import React, { useState } from 'react'
import { NavBar, TextArea, Toast } from 'antd-mobile'
import { useNavigate } from 'react-router'
import { commentAdd } from "../../service/movieService"

export default function Comment() {
  const [value, setValue] = useState('')
  let history = useNavigate()
  const back = () => history(-1)
  const right = (
    <div style={{ fontSize: 16 }} onClick={async () => {
      let res = await commentAdd({
        "content": value,
        "movieId": 1,
        "score": 5
      })
      if (res.data.code == 200) {
        Toast.show({
          icon: 'success',
          content: '发布评论成功',
        })
        setValue("")
      } else {
        Toast.show({
          icon: 'fail',
          content: '评论失败',
        })
      }
    }}>发布</div>
  )
  return (
    <div>
      <NavBar right={right} onBack={back}>
        我的讨论
      </NavBar>
      <TextArea
        placeholder='大家都在问:剧情怎么样,画面好吗?演技如何?'
        value={value}
        onChange={val => {
          setValue(val)
        }}
      />
    </div>
  )
}
